package com.rxjava.simpleio3;

/**
 * Created by iceGeneral on 2016/10/15.
 */
public class OnSubscribeLift<T, R> implements OnSubscribe<R> {

    final OnSubscribe<T> parent;
    final Operator<? extends R, ? super T> operator;

    public OnSubscribeLift(OnSubscribe<T> parent, Operator<? extends R, ? super T> operator) {
    	//parent -> subscriber.onNext(10);
    	//parent -> OnSubscribeLift对象(OperatorMap对象(return "map" + integer;))
    	//parent -> -> OnSubscribeLift对象(OperatorObserveOn对象)
        this.parent = parent;
        //operator -> OperatorMap对象(return "map" + integer;)
        //operator -> OperatorObserveOn对象
        //operator -> OperatorMap对象(return new User(name);)
        this.operator = operator;
    }

    @Override
    public void call(Subscriber<? super R> r) {
    	//r -> System.out.println(u);
    	//r -> MapSubscriber对象(System.out.println(u);return new User(name);)
    	//r -> handler.post
        System.out.println("step2");
        //operator -> OperatorMap对象(return new User(name);)
        //st -> MapSubscriber对象(System.out.println(u);return new User(name);)
        //st -> handler.post
        //st -> MapSubscriber对象(handler.post;return "map" + integer;)
        Subscriber<? super T> st = operator.call(r);
        System.out.println("step4");
        parent.call(st);
    }
}
